package com.woniuxy.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.sql.Date;

@Configuration
public class AutoFillConfig implements MetaObjectHandler {
    /**
     * 向数据库插入数据时，自动填充事件
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Date time = new Date(System.currentTimeMillis());
        this.fillStrategy(metaObject, "inputDate", time);
        this.fillStrategy(metaObject, "modifyTime", time);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Date time = new Date(System.currentTimeMillis());
        this.fillStrategy(metaObject, "modifyTime", time);
    }
}
